/*****************************
 *@file: PrizeDialog
 *@author: 陈吕唐
 *@desc: 抽奖弹窗
 *@date: 2024-03-22	16:14
 *****************************/
import { Button, _decorator, log } from 'cc';
import CharacterManageSingle from '../character/CharacteManageSingle';
import BDialog from '../libs/component/dialog/BDialog';
import BDialogBuilder from '../libs/component/dialog/BDialogBuilder';
import { CharacterDetailDialog } from './CharacterDetailDialog';
const { ccclass, property } = _decorator;

@ccclass('PrizeDialog')
export class PrizeDialog extends BDialog {
    /****************************************************************************************************************
     *Readonly 常量
     ****************************************************************************************************************/

    /****************************************************************************************************************
     *Property 定义变量
     ****************************************************************************************************************/

    /***************************************************************
     *PropertyUI 引用的控件
     ***************************************************************/
    @property({ group: { name: 'UI', id: '2' }, type: Button, tooltip: `抽取英雄按钮组件` })
    private prizeButton: Button = undefined!;
    /****************************************************************************************************************
     * Lifecycle 生命周期相关方法
     ****************************************************************************************************************/
    public static open() {
        let build = new BDialogBuilder();
        build.prefabPath = `dialog/PrizeDialog`;
        return build.build();
    }
    protected onLoad(): void {
        super.onLoad();
        this.prizeButton.node.on(Button.EventType.CLICK, this.prizeCharacter, this);
    }
    /****************************************************************************************************************
     * Public 公有方法
     ****************************************************************************************************************/

    /****************************************************************************************************************
     * private 私有方法
     ****************************************************************************************************************/
    private prizeCharacter() {
        let promise = CharacterManageSingle.single.prizeCharacter();
        promise.then(
            (value) => {
                // this.closeDialog();
                CharacterDetailDialog.open(value);
            }, (error) => {
                log(error);
            }
        )
    }
    /****************************************************************************************************************
     * Property Get && Set 属性的 get && set 函数
     ****************************************************************************************************************/

}

